<?php

use App\Http\Controllers\Admin\AdminUserController;
use App\Http\Controllers\Admin\CourseController;
use App\Http\Controllers\Index\IndexController as indexC;
use App\Http\Controllers\Admin\FileController;
use App\Http\Controllers\Admin\IndexController;
use App\Http\Controllers\Admin\LoginController;
use App\Http\Controllers\Admin\ResourceController;
use App\Http\Controllers\Admin\SettingController;
use App\Http\Controllers\Index\CourseController as CourseC;
use App\Models\Resource;
use Illuminate\Support\Facades\Route;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

// Route::get('/', function () {
//     return view('welcome');
// })->name('index');

// 创建首页路由
Route::get('/',[indexC::class,'index'])->name('index');

// 创建课程对应路由
Route::prefix('course')->group(function (){
    // 课程首页
    Route::get('/{course}',[CourseC::class,'index'])->name('course.index');
    // 课程阅读
    Route::get('/{course}/{resource}',[CourseC::class,'resource'])->name('course.resource');
    // 获取视频播放凭证
    Route::post('/getVideoPlayAuth',[CourseC::class,'getVideoPlayAuth'])->name('course.getVideoPlayAuth');
    // 测试阿里云VOD连接
    Route::get('/test-vod-connection',[CourseC::class,'testVodConnection'])->name('test.vod.connection');
    // 阿里云VOD测试页面
    Route::get('/test-vod-page', function() {
        return view('index.course.test-vod');
    })->name('test.vod.page');
});

// 创建路由分组
Route::prefix('admin')->group(function(){
    // 管理员登录与退出
    Route::get('login',[LoginController::class,'index'])->name('admin.login');
    Route::post('login',[LoginController::class,'check'])->name('admin.login');
    Route::get('logout' ,[LoginController::class,'logout'])->name('admin.logout');
    
    // 需要保护的路由列表
    Route::middleware(['adminLoginCheck'])->group(function(){
        // 后台中心的首页
        Route::get('index',[indexController::class,'index'])->name('admin.index');
        
        //管理员管理模块 
        Route::prefix('adminuser')->group(function(){
            // 列表
            Route::get('/',[AdminUserController::class,'index'])->name('admin.adminuser');

            // 添加、编辑共用
            Route::get('add/{adminuser?}',[AdminUserController::class,'add'])->name('admin.adminuser.add');
            Route::post('add/{adminuser?}',[AdminUserController::class,'save'])->name('admin.adminuser.add');

            //软删除
            Route::get('remove/{adminuser}',[AdminUserController::class,'remove'])->name('admin.adminuser.remove');
            Route::get('state/{adminuser}',[AdminUserController::class,'state'])->name('admin.adminuser.state');
        });

        // 系统设置模块
        Route::prefix('setting')->group(function(){
            Route::get("/",[SettingController::class,'index'])->name('admin.setting');
            Route::post('/',[SettingController::class,'save'])->name('admin.setting');
        });

        // 资源管理模块
        Route::prefix('resource')->group(function(){
            // 资源列表页
            Route::get('/',[ResourceController::class,'index'])->name('admin.resource');

            // 资源添加页
            Route::get('/add/{resource?}',[ResourceController::class,"add"])->name('admin.resource.add');
            Route::post('/add/{resource?}',[ResourceController::class,'save'])->name('admin.resource.add');

            // 资源移除页
            Route::get('remove/{resource}',[ResourceController::class,'remove'])->name('admin.resource.remove');

            // 编辑器上传图片
            Route::post('/up',[ResourceController::class,'up'])->name('admin.resource.up');
        });

        // 定义课程分组
        Route::prefix('course')->group(function(){
            // 课程列表页
            Route::get('/',[CourseController::class,'index'])->name('admin.course');
            
            // 课程详细页
            Route::get('{course}',[CourseController::class,'detail'])->name('admin.course.detail');

            // 课程编辑
            Route::get('/add/{course?}',[CourseController::class,'add'])->name('admin.course.add');
            Route::post('/add/{course?}',[CourseController::class,'save'])->name('admin.course.add');

            // 移除
            Route::get('/remove/{course}',[CourseController::class,'remove'])->name('admin.course.remove');

            // 章节子分组,之所以有这个参数，是因为我们添加章节必须要知道是哪个课程
            Route::prefix('{course}/chapter')->group(function(){
                // 章节添加
                Route::get('/add/{chapter?}',[CourseController::class,'chapterAdd'])->name('admin.course.chapter.add');
                Route::post('/add/{chapter?}',[CourseController::class,'chapterSave'])->name('admin.course.chapter.add');

                // 章节删除
                Route::get('/remove/{chapter?}',[CourseController::class,'chapterRemove'])->name('admin.course.chapter.remove');
            });

            // 资源管理
            Route::prefix('{course}/{chapter}/resource')->group(function(){
                Route::get('/add',[CourseController::class,'resourceAdd'])->name('admin.course.resource.add');
                Route::post('/add',[CourseController::class,'resourceSave'])->name('admin.course.resource.add');
            });

            // 文件管理
            Route::prefix('file')->group(function () {
                Route::get('/',[FileController::class,'index'])->name('admin.file');
                Route::get('/up',[FileController::class,'up'])->name('admin.file.up');
                Route::post('/up',[FileController::class,'save'])->name('admin.file.up');
            });
        });

    });
});
